import request from "./http";

interface Login {
    email:string;
    password:string
}

// 获取登录接口
const getlogin=(params:Login)=>{
    return request({
        method:'post',
        url:'user/login',
        data:params
    })
}
interface ListConfig {
    currentPage: number;
    pageSize: number
}

//  获取专栏列表信息

const columnslist = (options: ListConfig) => {
    return request({
        method: 'get',
        url: 'columns',
        params: options
    })
}

//单个专栏列表
interface oncecolumns {
    currentPage:number;
    pageSize:number;
    id: string;
}
const onceList =(params:oncecolumns)=>{
   return request({
     method: "get",
     url: `/columns/${params.id}/posts?currentPage=${params.currentPage}&pageSize=${params.pageSize}`
   })
}

// 专栏详情
interface ListKeys {
    id: number;
}

  function menusList(id:ListKeys){
    return request.get(`columns/?${id}`)
  }

  // 获得单个文章详情
const detailposts =(id:string)=>{
    return request({
        method: "get",
        url: `posts/${id}`
    })
}


//图片上传
const upload =(params:any)=>{
    return request({
        url:'/upload',
        method: "post",
        data: params
    })
}

 //获取用户信息  /api/user/current获取当前用户登录信息
 const getuser =()=>{
    return request({
       url:'/user/current'
    })
}

// 新建文章
const Createanewarticle =(params:any)=>{
    return request({
        url: "/posts",
        method: "post",
        data:params
    })
}
export {
    getlogin,
    getuser,
    columnslist,
    menusList,
    onceList,
    upload,
    Createanewarticle,
    detailposts
}